import Vue from "vue"
import Router from "vue-router"

Vue.use(Router)
import Layout from "@/layout"

// 公共路由
export const constantRoutes = [
	{
		path: "/redirect",
		component: Layout,
		hidden: true,
		children: [
			{
				path: "/redirect/:path(.*)",
				component: () => import("@/views/redirect")
			}
		]
	},
	{
		path: "/login",
		component: () => import("@/views/login"),
		hidden: true
	},
	{
		path: "/scrollLargeScreen",
		component: () => import("@/views/Home/ScrollLargeScreen"),
		hidden: true
	},
  {
		path: "/HomeIndexData",
		component: () => import("@/views/Home/HomeIndexData"),
		hidden: true
	},
	{
		path: "/dataBoard",
		component: () => import("@/views/Home/dataBoard"),
		hidden: true
	},
  {
		path: "/BigPingBoard",
		component: () => import("@/views/Home/BigPingBoard"),
		hidden: true
	},
	{
		path: "/register",
		component: () => import("@/views/register"),
		hidden: true
	},
	{
		path: "/404",
		component: () => import("@/views/error/404"),
		hidden: true
	},
	{
		path: "/401",
		component: () => import("@/views/error/401"),
		hidden: true
	},
	{
		path: "",
		component: Layout,
		redirect: "index",
		children: [
			{
				path: "index",
				component: () => import("@/views/Home/index"),
				name: "Index",
				meta: { title: "首页", icon: "dashboard", affix: true }
			}
		]
	},
	{
		path: "/user",
		component: Layout,
		hidden: true,
		redirect: "noredirect",
		children: [
			{
				path: "profile",
				component: () => import("@/views/system/user/profile/index"),
				name: "Profile",
				meta: { title: "个人中心", icon: "user" }
			}
		]
	}
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
	{
		path: "/system/user-auth",
		component: Layout,
		hidden: true,
		permissions: ["system:user:edit"],
		children: [
			{
				path: "role/:userId(\\d+)",
				component: () => import("@/views/system/user/authRole"),
				name: "AuthRole",
				meta: { title: "分配角色", activeMenu: "/system/user" }
			}
		]
	},
	{
		path: "/system/role-auth",
		component: Layout,
		hidden: true,
		permissions: ["system:role:edit"],
		children: [
			{
				path: "user/:roleId(\\d+)",
				component: () => import("@/views/system/role/authUser"),
				name: "AuthUser",
				meta: { title: "分配用户", activeMenu: "/system/role" }
			}
		]
	},
	{
		path: "/system/dict-data",
		component: Layout,
		hidden: true,
		permissions: ["system:dict:list"],
		children: [
			{
				path: "index/:dictId(\\d+)",
				component: () => import("@/views/system/dict/data"),
				name: "Data",
				meta: { title: "字典数据", activeMenu: "/system/dict" }
			}
		]
	},
	{
		path: "/monitor/job-log",
		component: Layout,
		hidden: true,
		permissions: ["monitor:job:list"],
		children: [
			{
				path: "index/:jobId(\\d+)",
				component: () => import("@/views/monitor/job/log"),
				name: "JobLog",
				meta: { title: "调度日志", activeMenu: "/monitor/job" }
			}
		]
	},
	{
		path: "/tool/gen-edit",
		component: Layout,
		hidden: true,
		permissions: ["tool:gen:edit"],
		children: [
			{
				path: "index/:tableId(\\d+)",
				component: () => import("@/views/tool/gen/editTable"),
				name: "GenEdit",
				meta: { title: "修改生成配置", activeMenu: "/tool/gen" }
			}
		]
	},
	{
		path: "/repair/repairProduct",
		component: Layout,
		hidden: true,
		permissions: ["erp:repair:repairProduct"],
		children: [
			{
				path: "repairProduct/index",
				component: () => import("@/views/repair/repairProduct/index"),
				name: "repairProduct",
				meta: { title: "返修单-产品列表", activeMenu: "/repair/repairProduct" }
			}
		]
	},
	{
		path: "/taskFilling/taskFill",
		component: Layout,
		hidden: true,
		permissions: ["erp:taskFilling:write", "erp:taskFilling:edit", "taskFilling:repair:change"],
		children: [
			{
				path: "writeContent/index",
				component: () => import("@/views/taskFilling/writeContent/index"),
				name: "writeContent",
				meta: { title: "填写工作单", activeMenu: "/taskFilling/writeContent" }
			},
			{
				path: "menuList/index",
				component: () => import("@/views/taskFilling/menuList/index"),
				name: "menuLists",
				meta: { title: "工作单", activeMenu: "/taskFilling/menuList" }
			},
			{
				path: "change/index",
				component: () => import("@/views/taskFilling/change/index"),
				name: "changeRepair",
				meta: { title: "换件单", activeMenu: "/taskFilling/change" }
			},
      // {
			// 	path: "repair/index",
			// 	component: () => import("@/views/taskFilling/repair/index"),
			// 	name: "repairChange",
			// 	meta: { title: "换件单", activeMenu: "/taskFilling/repair" }
			// }
		]
	},
	{
		path: "/army/unqualifieds",
		component: Layout,
		hidden: true,
		permissions: ["erp:unqualified:edit", "erp:unqualified:write"],
		children: [
			{
				path: "write/index",
				component: () => import("@/views/army/unqualified/write/index"),
				name: "writes",
				meta: { title: "填写工作单", activeMenu: "/army/unqualified/write/index" }
			}
		]
	},

	{
		path: "/quality/qualityInspections",
		component: Layout,
		hidden: true,
		permissions: ["erp:qualityInspection:edit"],
		children: [
			{
				path: "qualityInspection/index",
				component: () => import("@/views/quality/qualityInspection/index"),
				name: "qualityInspection",
				meta: { title: "填报工序", activeMenu: "/quality/qualityInspection/index" }
			}
		]
	},
	{
		path: "/filercv/rcvlists",
		component: Layout,
		hidden: true,
		permissions: ["filercv:fileList:edit"],
		children: [
			{
				path: "rcvlist/index",
				component: () => import("@/views/filercv/rcvlist/index"),
				name: "rcvlistList",
				meta: { title: "文件台账", activeMenu: "/filercv/rcvlist/index" }
			}
		]
	},

	{
		path: "/product/productSetting",
		component: Layout,
		hidden: true,
		permissions: ["erp:product:productPart", "erp:product:productMustPart"],
		children: [
			{
				path: "productPart/index/:id(\\d+)",
				component: () => import("@/views/product/productPart/index"),
				name: "productPart",
				meta: { title: "零组件", activeMenu: "/product/productPart" }
			},
			{
				path: "productMustPart/index/:id(\\d+)",
				component: () => import("@/views/product/productMustPart/index"),
				name: "productMustPart",
				meta: { title: "必换件", activeMenu: "/product/productMustPart" }
			}
		]
	},
	{
		path: "/productTechnology/Technology",
		component: Layout,
		hidden: true,
		permissions: ["erp:productTechnology:approve", "erp:productTechnologyVersions:design", "erp:productTechnologyName:process", "erp:productProcess:steps", "erp:productProcessStep:componentes"],
		children: [
			{
				path: "productTechnologyVersions/index",
				component: () => import("@/views/productTechnology/productTechnologyVersions/index"),
				name: "ProductTechnologyVersions",
				meta: { title: "工艺流程版本", activeMenu: "/productTechnology/productTechnologyVersions" }
			},
			{
				path: "productTechnologyName/index",
				component: () => import("@/views/productTechnology/productTechnologyName/index"),
				name: "productTechnologyName",
				meta: { title: "工艺流程列表", activeMenu: "/productTechnology/productTechnologyName" }
			},
			{
				path: "productProcess/index",
				component: () => import("@/views/productTechnology/productProcess/index"),
				name: "productProcess",
				meta: { title: "产品工序", activeMenu: "/productTechnology/productProcess" }
			},
			{
				path: "productProcessStep/index",
				component: () => import("@/views/productTechnology/productProcessStep/index"),
				name: "productProcessStep",
				meta: { title: "工序步骤", activeMenu: "/productTechnology/productProcessStep" }
			},
			{
				path: "productProcessStepPart/index",
				component: () => import("@/views/productTechnology/productProcessStepPart/index"),
				name: "productProcessStepPart",
				meta: { title: "工序步骤-零组件", activeMenu: "/productTechnology/productProcessStepPart" }
			}
		]
	},
	{
		path: "/attachment",
		component: Layout,
		hidden: true,
		permissions: [
			"erp:quality:files",
			"erp:auxiliaryConsumables:edit",
			"erp:propertyRegistrationRecord:file",
			"erp:task:files",
			"erp:synthesize:file",
			"erp:repair:files",
			"erp:taskFilling:files",
			"erp:product:productPart",
			"erp:product:productMustPart",
			"erp:device:annex",
			"measuringEquipment:equipment:annex",
			"Instrument:instrument:annex",
			"Repair:Repair:annex",
			"Repair:Repair:annex2",
			"plan:production:annex",
			"plan:maintain:annex",
			"plan:maintainTask:annex",
			"fault:faultlist:annex",
			"fault:faultlist:annex2",
			"taskFilling:repairList:annex",
			"army:armycheck:annex",
			"army:armycheck:annex2",
			"army:armylist:annex",
			"synthesize:outsource:oentrance:annex",
			"synthesize:outsource:oentrance:annex2",
			"synthesize:store:sinspect:annex",
			"synthesize:store:sinspect:annex2",
			"synthesize:store:sinspectlist:HG",
			"synthesize:store:sinspectlist:annex",
			"synthesize:store:sinspectlist:annex2",
			"synthesize:sentrance:annex",
			"synthesize:sentrance:annex2",
			"synthesize:sentrancelist:annex",
			"synthesize:sentrancelist:annex2",
			"quality:customer:coutsource:annex",
			"quality:customer:coutsource:annex2",
			"quality:stock:sentrance:annex",
			"quality:stock:sentrance:annex2",
			"quality:customer:oentrance:annex",
			"quality:customer:oentrance:annex2",
			"quality:stock:inspect:annex",
			"quality:qualityExam:annex",
			"quality:qualityExam2:annex",
			"quality:qmeasure:annex",
			"quality:qtask:annex",
			"RedundantController:RedundantController:annex2",
			"RedundantController:RedundantController:annex",
			"finance:contract:annex",
			"finance:invoice:annex",
			"equipApply:applylist:annex"
		],
		children: [
			{
				path: "attachmentUpload",
				component: () => import("@/views/attachmentUpload"),
				name: "attachmentUpload",
				meta: { title: "附件列表", activeMenu: "/attachmentUpload" }
			}
		]
	}
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push
let routerReplace = Router.prototype.replace
// push
Router.prototype.push = function push(location) {
	return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
	return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
	mode: "history", // 去掉url中的#
	scrollBehavior: () => ({ y: 0 }),
	routes: constantRoutes
})
